package main

import "fmt"

//二叉查找算法
//对已经排号的有序数组
//数组存在多次以找到第一个为准

func main()  {
	// 搜索数组
	array := []int{2,4,5,6,7,12,14,15,18,19,23,25,26,27,30,44,65}
	BinarySearch(&array, 0,len(array)-1,25)
	fmt.Println(array[11])
}

func BinarySearch(array *[]int,leftIndex int,rightIndex int,findValue int)  {
	if leftIndex > rightIndex {
		fmt.Println("没有找到数值")
	}
	middle:= (leftIndex+rightIndex)/2
	if (*array)[middle] > findValue{
		BinarySearch(array,leftIndex,middle-1,findValue)
	}else if (*array)[middle] < findValue {
		BinarySearch(array,leftIndex,rightIndex+1,findValue)
	}else {
		fmt.Println("数值找到%v",middle)
	}
}